/**
 * @typedef {Object} ShapeOptions
 * @property {HTMLCanvasElement?} canvas
 * @property {number} x
 * @property {number} y
 * @property {number} height
 * @property {number} width
 * @property {boolean} listen
 */

class Shape {
  /**
   * @description canvas
   * @type {HTMLCanvasElement}
   */
  canvas;

  /**
   * @description ctx
   * @type {CanvasRenderingContext2D}
   */
  ctx;

  /**
   * @description x
   * @type {number}
   */
  x;

  /**
   * @description y
   * @type {number}
   */
  y;

  /**
   * @description width
   * @type {number}
   */
  width;

  /**
   * @description height
   * @type {number}
   */
  height;

  /**
   * @description 启用监听事件
   * @type {boolean}
   */
  listen;

  /**
   * @description 事件
   * @type {ShapeEvent}
   */
  event = new ShapeEvent();

  /**
   * @description 可拖拽
   * @type {boolean}
   */
  draggable = false;

  /**
   * @description 构造函数
   * @param {ShapeOptions} options
   */
  constructor(options) {
    this.canvas = options.canvas ?? null;
    this.ctx = this.canvas?.getContext("2d") || null;
    this.x = options.x;
    this.y = options.y;
    this.width = options.width;
    this.height = options.height;
    this.listen = options.listen ?? true;
  }

  /**
   * @description 添加监听事件
   * @param {string} type
   * @param {(...args)=>void} callback
   */
  addEventListener(type, callback) {
    this.event.add(type, callback);
  }

  /**
   * @description 移除监听事件
   * @param {string} type
   */
  removeEventListener(type) {
    this.event.remove(type);
  }

  contains() {
    throw Error("子类应覆盖此方法");
  }

  draw() {
    throw Error("子类应覆盖此方法");
  }
}
